package com.lsfb.signln.Statistics.codescan;


import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.Window;

import com.zgscwjm.lsfbbasetemplate.Event.LsfbEvent;
import com.zgscwjm.lsfbbasetemplate.annotation.ViewInjectUtils;
import com.zgscwjm.lsfbbasetemplate.utils.T;

/**
 * Initial the camera 二维码扫描 -----弃用
 * 
 * @author Ryan.Tang
 */
//@ContentView(R.layout.aty_chanpin_shibie)
public class MipcaActivityCaptureActivity extends FragmentActivity {

//	@ViewInject(R.id.actmy_title)
//	LsfbTitleBar titleBar;

	@Override
	protected void onCreate(@Nullable Bundle arg0) {
		// TODO Auto-generated method stub
		super.onCreate(arg0);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		ViewInjectUtils.inject(this);
		LsfbEvent.getInstantiation().register(this);
		GetCAMEARPermission();
		initData();
	}

	public void initData() {
		final int RESULT_CODE=101;

		Intent intent=new Intent();
		intent.putExtra("second", "I am second!");
		setResult(RESULT_CODE, intent);



//		MipcaActivityCapture mip = new MipcaActivityCapture();
//		Bundle budle = new Bundle();
//		budle.putString("hastitle", "1");
//		mip.setArguments(budle);
//		getSupportFragmentManager().beginTransaction()
//				.replace(R.id.content, mip).commit();

		// getFragmentManager().beginTransaction().replace(R.id.content, mip);

	}

	public void initEvent() {
		// TODO Auto-generated method stub

	}

	public void initView() {
		// TODO Auto-generated method stub
	}

	/**
	 * 相机权限的请求
	 */
	private final int carmera = 88;
	public void GetCAMEARPermission() {

		if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
			ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA},
					carmera);
		} else {
			Log.e("nonsense", "相机开启");
		}
	}



	@Override
	public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
		super.onRequestPermissionsResult(requestCode, permissions, grantResults);
		switch (requestCode) {
			case carmera:
				if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
					T.showShort(this, "请求权限成功");
				} else {

					T.showShort(this, "请求权限失败");
				}
				break;

		}
	}


}